package com.szewec.fsd.service.[[module]].controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.szewec.fsd.api.[[module]].entity.[[entity.name]];
import com.szewec.fsd.api.[[module]].vo.[[entity.name]]DtoVo;
import com.szewec.fsd.common.data.model.PageSearcher;
import com.szewec.fsd.service.[[module]].service.I[[entity.name]]Service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.szewec.fsd.common.data.mybatisplus.PageRender;
import com.szewec.fsd.common.data.mybatisplus.SearchRender;
import com.szewec.fsd.common.core.model.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import lombok.extern.slf4j.Slf4j;

/**
 * [[entity.comment]]Controller
 * @version 1.0
 * @author: [[authorInfo.author]]
 * @date: [[authorInfo.timestamp]]
 */
@Slf4j
@RestController
@RequestMapping("/[[module]]/[[entity.beanName]]")
@Api(value = "[[module]]/[[entity.beanName]]", tags = "[[entity.comment]]")
public class [[entity.name]]Controller {
	@Autowired
    public I[[entity.name]]Service [[entity.beanName]]Service;

    @ApiOperation("[[entity.comment]]分页列表")
    @PostMapping("/page")
    public R<Page> queryPage(@RequestBody PageSearcher<Page, [[entity.name]]DtoVo> pageSearcher) {
        PageRender.setOrderItem(pageSearcher.getPage());
        Wrapper<[[entity.name]]> queryWrapper = SearchRender.renderSearchQueryWrapper(pageSearcher.getSearchDto());
        return R.ok([[entity.beanName]]Service.page(pageSearcher.getPage(), queryWrapper));
    }

    @ApiOperation("[[entity.comment]]列表")
    @PostMapping("/list")
    public R<List<[[entity.name]]>> list(@RequestBody [[entity.name]]DtoVo [[entity.beanName]]DtoVo) {
        return R.ok([[entity.beanName]]Service.list(Wrappers.query([[entity.beanName]]DtoVo)));
    }

    @ApiOperation("[[entity.comment]]添加")
    @PostMapping("/insert")
    public R<Boolean> insert(@RequestBody [[entity.name]]DtoVo [[entity.beanName]]DtoVo) {
    	return R.ok([[entity.beanName]]Service.save([[entity.beanName]]DtoVo));
    }

    @ApiOperation("[[entity.comment]]修改")
    @PostMapping("/update")
    public R<Boolean> update(@RequestBody [[entity.name]]DtoVo [[entity.beanName]]DtoVo) {
    	return R.ok([[entity.beanName]]Service.updateById([[entity.beanName]]DtoVo));
    }


    @ApiOperation("[[entity.comment]]删除")
    @PostMapping("/delete")
    public R<Boolean> delete(@RequestParam("id") Long id) {
        return R.ok([[entity.beanName]]Service.removeById(id));
    }


    @ApiOperation("[[entity.comment]]删除")
    @PostMapping("/deleteBatch")
    public R<Boolean> deleteBatch(@RequestBody List<Long> ids){
        return R.ok([[entity.beanName]]Service.removeByIds(ids));
    }

    @ApiOperation("[[entity.comment]]详情")
    @GetMapping("/detail")
    public R<[[entity.name]]> detail(@RequestParam("id") Long id) {
        return R.ok([[entity.beanName]]Service.getById(id));
    }

}
